import {
	RsaAesEncrypt,
	RsaAesDecrypt
} from './commonCrypto';
import globalConfig from './globalConfig';

// 加密
export const encrypt = (data) => {
	let publicKey = globalConfig.publicKey;
	let value = JSON.stringify(data)
	// 加密
	let encrypted = RsaAesEncrypt(publicKey, value);

	let params = {
		AesEncryptData: encrypted.data,
		AesDecryptData: null,
		RsaEncryptAesKey: encrypted.key
	};

	return params
}

// 解密
export const decrypt = ({
	key,
	data
}) => {
	let privateKey = globalConfig.privateKey;
	let decrypted = RsaAesDecrypt(privateKey, key, data);

	return decrypted
}

// //AES+RSA加密及解密示例
// let publicKey = globalConfig.publicKey;
// let privateKey = globalConfig.privateKey;

// let data = JSON.stringify({
// 	EnterpriseWeChatID: 'Lanyangyang'
// });
// // 加密
// let encrypted = RsaAesEncrypt(publicKey, data);
// // 解密
// let decrypted = RsaAesDecrypt(privateKey, encrypted.key, encrypted.data);

// let params = {
// 	AesEncryptData: encrypted.data,
// 	AesDecryptData: null,
// 	RsaEncryptAesKey: encrypted.key
// };

// console.log(decrypted, '解密');

// 根据userAgent判断是否在手机上浏览
export const isMobile = () => {
	const u = navigator.userAgent;
	// console.log(u,'userAgent');
	//通过正则表达式的test方法判断是否包含“Mobile”字符串
	const isPhone = /mobile/i.test(u);
	// 判断屏幕
	const widthSize = window.innerWidth < 760

	// console.log(isPhone, '为true就是代表在手机');
	// console.log(widthSize, '为true就是代表屏幕小于760');
	// console.log(isPhone && widthSize,'为true就是肯定在就是浏览');

	return isPhone && widthSize;
};